<?php

/**
 * User E-Mail validator
 * Checks weather specified Login and E-Mail match
 *
 */
class Application_Form_RecoverValidator extends Zend_Validate_Abstract
{

    protected $_messageTemplates = array(
        'emailNotMatch' => "Given E-Mail do not match"
    );
    
    /**
     * Validate interface isValid function
     *
     * @param string $value
     * @return bool
     */
    public function isValid($value,$context=null)
    {
        if (empty($value)) return false;
        
        $this->_setValue($value);

        $userDb=new Application_Model_UserDb();
        
        $user=$userDb->fetchUserByEmail($value);
        
        if (!$user->isRegistered())
        {
            $this->_error('emailNotMatch');
            return false;
        }
        
        if ($user->login != $context['login'])
        {
            $this->_error('emailNotMatch');
            return false;
        }
        
        return true;
    }
}